package org.bdware.doip.core.codec.packet;

import io.netty.channel.ChannelHandlerContext;
import org.bdware.doip.core.doipMessage.MessageEnvelope;

import java.util.HashMap;

public class NoAckEnvelopeSendBuffer extends AbstractEnvelopeSendBuffer{

    HashMap<Integer, MessageEnvelope> envelopeBuffer;

    public NoAckEnvelopeSendBuffer(int requestId) {
        super(requestId);
        envelopeBuffer = new HashMap<>();
    }

    @Override
    public void pushToBuffer(MessageEnvelope env) {
        envelopeBuffer.put(env.sequenceNumber,env);
    }

    @Override
    public boolean receiveAck(MessageEnvelope env) {
        if(isCompleted) return true;
        if(env.sequenceNumber == -1){
            isCompleted = true;
        }else{
            isCompleted = false;
        }
        return isCompleted;
    }
}